// 引入mock.js
let Mock = require('mockjs')
let Random = Mock.Random

function shows () {
  console.log('演出数据变化')
  const showsinfo = [
    {
      'id': 1,
      'path': 'mxhdjy',
      'theaterShows': Mock.mock({
        'showInfo|70-100': [
          {
            'id': function () {
              let id = Random.guid()
              return id
            },
            'nameData|10-15': 1,
            'showName|+1': function () {
              let name = Random.csentence(4, this.nameData)
              return name
            },
            'pic': Random.image('268x356', '#4A7BF7', 'MXH ShowImg'),
            'fromNowOn|-20-200': 1,
            'now': '@now("yyyy-MM-dd")',
            'date|+1': function () {
              let now = new Date(this.now)
              now.setTime(now.getTime() + this.fromNowOn * 24 * 60 * 60 * 1000)
              let sub = now
              let year = sub.getFullYear()
              let month = sub.getMonth() + 1 < 10 ? '0' + (sub.getMonth() + 1) : (sub.getMonth() + 1)
              let day = sub.getDate() < 10 ? '0' + sub.getDate() : sub.getDate()
              return year + '-' + month + '-' + day
            },
            'priceData|4-5': 1,
            'priceStar|0-5': 1,
            'priceRange': function () {
              let price = [80, 100, 180, 360, 480, 550, 888, 1088, 1288, 1688]
              let range = []
              for (let i = 0; i < this.priceData; i++) {
                let priceR = {
                  class: i,
                  price: price[this.priceStar + i]
                }
                range.push(priceR)
              }
              return range
            },
            'price': function () {
              return `${this.priceRange[0].price}-${this.priceRange[this.priceData - 1].price}`
            },
            'type|1': ['音乐会', '歌剧', '戏剧', '音乐剧', '舞蹈/舞剧', '儿童剧', '演唱会', '戏曲', '综艺', '艺术活动', '秀', '音乐剧场', '其他'],
            'theater': 'mxhdjy',
            'theaterName': '梅溪湖大剧院',
            'hall|1': ['大剧场', '小剧场（多功能厅）'],
            // 生成简单的价格图
            'pricemap': function () {
              // 获取所在剧场
              let hall = ['大剧场', '小剧场（多功能厅）']
              let index = hall.indexOf(this.hall)
              // 获取所在剧场的座位数据
              let hallseat = [52, 30]
              let hallwidth = [76, 30]
              let seat = hallseat[index]
              let width = hallwidth[index]
              // size代表每个等级占有几行
              let size = Math.floor(seat / this.priceData)
              // mod代表会剩下几行，全部给最后一个等级
              let mod = seat % this.priceData
              let pricemap = []
              for (let i = 0; i <= this.priceData - 1; i++) {
                // i 是当前座位等级
                let pm = {}
                pm.price = this.priceRange[i].price
                pm.class = i
                pm.id = []
                // j 是代表当前行数 k是当前座位号
                // rowstar是开始行数 rowend是结束行数
                // 这里从i=0的时候对应的是最后一个等级
                let rowend = (this.priceData - i) * size
                let rowstar = rowend - size - 1
                if (rowstar < 0) { rowstar = 0 }
                if (i === 0) { rowend = rowend + mod }
                // console.log(seat, rowstar, size, rowend, i)
                for (let j = rowstar; j < rowend; j++) {
                  for (let k = 0; k < width; k++) {
                    let seat = j + '-' + k
                    pm.id.push(seat)
                  }
                }
                pricemap.push(pm)
              }
              return pricemap
            }
          }
        ]
      })
    },
    {
      'id': 2,
      'path': 'hndjy',
      'theaterShows': Mock.mock({
        'showInfo|70-150': [
          {
            'id': function () {
              let id = Random.guid()
              return id
            },
            'nameData|10-15': 1,
            'showName|+1': function () {
              let name = Random.csentence(4, this.nameData)
              return name
            },
            'pic': Random.image('268x356', '#4A7BF7', 'HNDJY ShowImg'),
            'fromNowOn|-20-200': 1,
            'now': '@now("yyyy-MM-dd")',
            'date|+1': function () {
              let now = new Date(this.now)
              now.setTime(now.getTime() + this.fromNowOn * 24 * 60 * 60 * 1000)
              let sub = now
              let year = sub.getFullYear()
              let month = sub.getMonth() + 1 < 10 ? '0' + (sub.getMonth() + 1) : (sub.getMonth() + 1)
              let day = sub.getDate() < 10 ? '0' + sub.getDate() : sub.getDate()
              return year + '-' + month + '-' + day
            },
            'priceData|4-5': 1,
            'priceStar|0-5': 1,
            'priceRange': function () {
              let price = [80, 100, 180, 360, 480, 550, 888, 1088, 1288, 1688]
              let range = []
              for (let i = 0; i < this.priceData; i++) {
                let priceR = {
                  class: i,
                  price: price[this.priceStar + i]
                }
                range.push(priceR)
              }
              return range
            },
            'price': function () {
              return `${this.priceRange[0].price}-${this.priceRange[this.priceData - 1].price}`
            },
            'type|1': ['音乐会', '歌剧', '戏剧', '音乐剧', '舞蹈/舞剧', '儿童剧', '演唱会', '戏曲', '综艺', '艺术活动', '秀', '音乐剧场', '其他'],
            'hall|1': ['大剧场', '话剧小剧场'],
            'theater': 'hndjy',
            'theaterName': '湖南大剧院',
            'pricemap': function () {
              // 获取所在剧场
              let hall = ['大剧场', '话剧小剧场']
              let index = hall.indexOf(this.hall)
              // 获取所在剧场的座位数据
              let hallseat = [51, 20]
              let hallwidth = [47, 20]
              let seat = hallseat[index]
              let width = hallwidth[index]
              // size代表每个等级占有几行
              let size = Math.floor(seat / this.priceData)
              // mod代表会剩下几行，全部给最后一个等级
              let mod = seat % this.priceData
              let pricemap = []
              for (let i = 0; i <= this.priceData - 1; i++) {
                // i 是当前座位等级
                let pm = {}
                pm.price = this.priceRange[i].price
                pm.class = i
                pm.id = []
                // j 是代表当前行数 k是当前座位号
                // rowstar是开始行数 rowend是结束行数
                // 这里从i=0的时候对应的是最后一个等级
                let rowend = (this.priceData - i) * size
                let rowstar = rowend - size - 1
                if (rowstar < 0) { rowstar = 0 }
                if (i === 0) { rowend = rowend + mod }
                // console.log(seat, rowstar, size, rowend, i)
                for (let j = rowstar; j < rowend; j++) {
                  for (let k = 0; k < width; k++) {
                    let seat = j + '-' + k
                    pm.id.push(seat)
                  }
                }
                pricemap.push(pm)
              }
              return pricemap
            }
          }
        ]
      })
    },
    {
      'id': 3,
      'path': 'csyyt',
      'theaterShows': Mock.mock({
        'showInfo|40-90': [
          {
            'id': function () {
              let id = Random.guid()
              return id
            },
            'nameData|10-15': 1,
            'showName|+1': function () {
              let name = Random.csentence(4, this.nameData)
              return name
            },
            'pic': Random.image('268x356', '#4A7BF7', 'CSYYT ShowImg'),
            'fromNowOn|-20-200': 1,
            'now': '@now("yyyy-MM-dd")',
            'date|+1': function () {
              let now = new Date(this.now)
              now.setTime(now.getTime() + this.fromNowOn * 24 * 60 * 60 * 1000)
              let sub = now
              let year = sub.getFullYear()
              let month = sub.getMonth() + 1 < 10 ? '0' + (sub.getMonth() + 1) : (sub.getMonth() + 1)
              let day = sub.getDate() < 10 ? '0' + sub.getDate() : sub.getDate()
              return year + '-' + month + '-' + day
            },
            'priceData|4-5': 1,
            'priceStar|0-5': 1,
            'priceRange': function () {
              let price = [80, 100, 180, 360, 480, 550, 888, 1088, 1288, 1688]
              let range = []
              for (let i = 0; i < this.priceData; i++) {
                let priceR = {
                  class: i,
                  price: price[this.priceStar + i]
                }
                range.push(priceR)
              }
              return range
            },
            'price': function () {
              return `${this.priceRange[0].price}-${this.priceRange[this.priceData - 1].price}`
            },
            'type|1': ['音乐会', '歌剧', '演唱会', '戏曲', '艺术活动', '秀', '音乐剧场', '其他'],
            'hall|1': ['交响乐大厅（湘江大厅）', '多功能厅（麓山中厅）', '室内乐厅（橘洲小厅）'],
            'theater': 'csyyt',
            'theaterName': '长沙音乐厅',
            'pricemap': function () {
              // 获取所在剧场
              let hall = ['交响乐大厅（湘江大厅）', '多功能厅（麓山中厅）', '室内乐厅（橘洲小厅）']
              let index = hall.indexOf(this.hall)
              // 获取所在剧场的座位数据
              let hallseat = [53, 21, 15]
              let hallwidth = [96, 50, 46]
              let seat = hallseat[index]
              let width = hallwidth[index]
              // size代表每个等级占有几行
              let size = Math.floor(seat / this.priceData)
              // mod代表会剩下几行，全部给最后一个等级
              let mod = seat % this.priceData
              let pricemap = []
              for (let i = 0; i <= this.priceData - 1; i++) {
                // i 是当前座位等级
                let pm = {}
                pm.price = this.priceRange[i].price
                pm.class = i
                pm.id = []
                // j 是代表当前行数 k是当前座位号
                // rowstar是开始行数 rowend是结束行数
                // 这里从i=0的时候对应的是最后一个等级
                let rowend = (this.priceData - i) * size
                let rowstar = rowend - size - 1
                if (rowstar < 0) { rowstar = 0 }
                if (i === 0) { rowend = rowend + mod }
                // console.log(seat, rowstar, size, rowend, i)
                for (let j = rowstar; j < rowend; j++) {
                  for (let k = 0; k < width; k++) {
                    let seat = j + '-' + k
                    pm.id.push(seat)
                  }
                }
                pricemap.push(pm)
              }
              return pricemap
            }
          }
        ]
      })
    }
  ]
  return showsinfo
}

// 以api路径为值，将testList函数暴露出去
exports.shows = shows
